package com.sc.sc250601.cook.config;

import com.sc.sc250601.cook.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    private final TokenInterceptor tokenInterceptor;

    public InterceptorConfig(TokenInterceptor tokenInterceptor) {
        this.tokenInterceptor = tokenInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截规则
        // 传入拦截器对象
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**") // 配置哪些请求拦截
                .excludePathPatterns("/login","/reg"); // 配置哪些请求不拦截
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
